﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

using Api.Hub.Constraints;
using Api.Hub.MessageHandlers;
using Api.Hub.ConstraintResolvers;

namespace Api.WebHost
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            //Register custom MessageHandler
            config.MessageHandlers.Add(new AddCustomHeader());

            //注册  自定义行内约束  解析器
            config.MapHttpAttributeRoutes(new ExtendDefaultConstraintResolver());

            #region 添加响应数据格式(xml|json)
            //config.Formatters.Clear();
            //config.Formatters.Add(new System.Net.Http.Formatting.JsonMediaTypeFormatter());
            #endregion

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: new { id = new Int32RangeConstraint(1, 1000) }
            );
        }
    }
}